/**
 * 封装一些常用的 ElementUI 消息组件
 */
import { Notification, MessageBox } from "element-ui";

// 通知显示时间
const defaultDuration = 2000;

/**
 * @param {string} type 通知类型
 * @param {string} operate 操作类型
 * @param {string} msg 提示信息，可选
 * @param {number} duration 显示时间，可选
 */
export function notify(type, operate, msg, duration) {
  let notificationOptions = {
    title: getTitle(type, operate),
    type: opt[type],
    duration: duration || defaultDuration, // 使用传入的duration或默认值
  };

  if (msg && msg !== "") {
    notificationOptions.message = msg;
  }

  Notification(notificationOptions);
}

const opt = {
  1: "success",
  2: "error",
  3: "warning",
  4: "warning",
};

// 获取标题的辅助函数
function getTitle(type, operate) {
  switch (type) {
    case 1:
      return operate + "成功";
    case 2:
      return operate + "失败";
    case 3:
      return "已取消" + operate;
    default:
      return operate;
  }
}

// 使用示例
// notify(1, "操作", "这是成功的消息", 3000);

export const DEL = "删除";
export const UPD = "修改";
export const ADD = "新增";
export const EXP = "导出";

/**
 * 对话框通知
 */
export function confirm(message) {
  return MessageBox.confirm(message, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  });
}
